﻿// This code is released under the BSD license.
namespace PugLib.UnitTest
{
    #region

    using System;
    using Extensions;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    #endregion

    /// <summary>
    ///This is a test class for DateTimesTest and is intended
    ///to contain all DateTimesTest Unit Tests
    ///</summary>
    [TestClass]
    public class DateTimesTest
    {
        /// <summary>
        ///A test for WeekendsBetween
        ///</summary>
        [TestMethod]
        public void WeekendsBetweenTest()
        {
            DateTime start = new DateTime(2008, 1, 1);
            DateTime end = new DateTime(2008, 2, 21);
            const float expected = 7F;
            float actual = start.WeekendsBetween(end);
            Assert.AreEqual(expected, actual);

            start = new DateTime(2008, 2, 21);
            end = new DateTime(2008, 1, 1);
            actual = start.WeekendsBetween(end);
            Assert.AreEqual(expected, actual);
        }


        [TestMethod]
        public void TimeAgoTest()
        {
            DateTime date = DateTime.Now;
            for (int i = 0; i < 735; ++i)
            {
                date.AddDays(-1 * i).TimeAgo();
            }

            for (int i = 0; i < 125; ++i)
            {
                date.AddMinutes(-1 * i).TimeAgo();
            }
        }

        [TestMethod]
        public void HoursFromNowTest()
        {
            DateTime input = DateTime.Now;

            double number = 2F;
            DateTime expected = input.AddHours(number);
            DateTime actual = input.HoursFromNow(number);
            Assert.AreEqual(expected, actual);

            number = -2F;
            expected = input.AddHours(number);
            actual = input.HoursFromNow(number);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void HoursAgoTest()
        {
            DateTime input = DateTime.Now;

            double number = -2F;
            DateTime expected = input.AddHours(-number);
            DateTime actual = input.HoursAgo(number);
            Assert.AreEqual(expected, actual);

            number = 2F;
            expected = input.AddHours(-number);
            actual = input.HoursAgo(number);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void GetHourTextTest()
        {
            for (int i = 0; i < 15; ++i)
            {
                DateTimes.GetHourText(i);
            }
        }

        [TestMethod]
        public void ConvertToRelativeTimeTest()
        {
            DateTime input = DateTime.Today;
            for (int i = 0; i < 1440; ++i)
            {
                input.AddMinutes(i).ConvertToRelativeTime();
            }
        }
    }
}